﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business;
using Database;
using System.Globalization;


namespace DT5_Anh09110006_Hung09110044_Vu09110157.QuanLy
{
    public partial class ChiTietLopHoc : System.Web.UI.Page
    {
        Business.QuanLyLopHoc qllophoc = new Business.QuanLyLopHoc();
        Business.QuanLyHocVien_LopHoc qlhv_lop = new Business.QuanLyHocVien_LopHoc();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["MaLopHoc"] != null)
                {
                    loaddulieu();
                }
                else
                {
                    Response.Redirect("QuanLyLopHoc.aspx");
                }
            }
          

        }
        private void loaddulieu()
        {
            String malophoc = Session["MaLopHoc"].ToString();
            LopHoc lop = qllophoc.LayLopHocTheoMa(malophoc);
            lblMaLop.Text = lop.MaLop;
            lblbGV.Text = lop.GiaoVienPT;
            lblPhongHoc.Text = lop.PhongHoc;
            lblHocPhi.Text = lop.HocPhi.ToString();
            lblSiSo.Text = lop.SiSo.ToString();
            lblNgayKhaiGiang.Text = lop.NgayKhaiGiang.Value.ToString("MM/dd/yyyy");
            lblLichHoc.Text = lop.LichHoc;
            lblMota.Text = lop.MoTa;
            grvHocVien.DataSource = qlhv_lop.LayDanhSachHocVienCuaLop(Session["MaLopHoc"].ToString());
            grvHocVien.DataBind();
        }

        protected void btnQuayLai_Click(object sender, EventArgs e)
        {
            Session["MaLopHoc"] = null;
            Response.Redirect("QuanLyLopHoc.aspx");
        }

        protected void grvHocVien_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grvHocVien.PageIndex = e.NewPageIndex;
            grvHocVien.DataSource = qlhv_lop.LayDanhSachHocVienCuaLop(Session["MaLopHoc"].ToString());
            grvHocVien.DataBind();
        }

        protected void grvHocVien_RowCommand(object sender, GridViewCommandEventArgs e)
        {
           
            if (e.CommandName.Equals("Sua"))
            {
                Session["MaHocVien"] = e.CommandArgument;
                Response.Redirect("SuaHocVienLopHoc.aspx");
            }
            if (e.CommandName.Equals("Xoa"))
            {
                if (qlhv_lop.XoaHocVien(Session["MaLopHoc"].ToString(), e.CommandArgument.ToString()))
                {

                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "redirectMe", "alert('Không thể xóa học viên này');", true);
                }
                loaddulieu();
            }

        }

        protected void btnThemHV_Click(object sender, EventArgs e)
        {
            Response.Redirect("ThemHocVienLopHoc.aspx");

        }
    }
}